using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;

public class UiVolumeSlider : MonoBehaviour
{
    public string parameter;
    public Slider Slider { get; private set; }
    private AudioMixer audioMixer;

    private void Awake()
    {
        audioMixer = Resources.Load<AudioMixer>("Audio/AudioMixer");
        Slider = GetComponent<Slider>();
    }

    public void SliderValue(float value)
    {
        float db = Mathf.Log10(value) * 20; // 用于将线性值转换为分贝值
        _ = audioMixer.SetFloat(parameter, db);
    }

    public void Load(float value)
    {
        if (value >= 0.0001f)
        {
            Slider.value = value;
        }
    }
}
